import Vue from 'vue';
import Router from 'vue-router';
import Home from '@/views/Home.vue'
import buyList from '@/views/buyList.vue'
import indexMain from '@/views/indexMain.vue'
import purchaseList from '@/views/purchaseList.vue'

import buyDetail from '@/views/buyDetail.vue'
import purDetail from '@/views/purDetail.vue'
import userIndex from '@/views/user/userIndex.vue'
import myInfo from '@/views/user/myInfo.vue'
import myNotice from '@/views/user/myNotice.vue'
import myRed from '@/views/user/myRed.vue'
import myOutRecord from '@/views/user/myOutRecord.vue'
import mySaling from '@/views/user/mySaling.vue'
import myBuying from '@/views/user/myBuying.vue'
import wantToSale from '@/views/wantToSale.vue'
import toSendGoods from '@/views/toSendGoods.vue'

Vue.use(Router);

let routers = new Router({
    routes: [{
            path: '/',
            component: Home,
            redirect: 'index',
            name: '首页',
            children: [{
                path: '/index',
                component: indexMain,
                name: '主页',
            }, {
                path: '/wantToSale',
                component: wantToSale,
                name: '我要卖',
            }, {
                path: '/toSendGoods',
                component: toSendGoods,
                name: '添加商品信息',
            }, {
                path: '/buyList',
                component: buyList,
                name: '我要买',
            }, {
                path: '/purchaseList',
                component: purchaseList,
                name: '求购信息',
            }, {
                path: '/buyDetail/:id',
                component: buyDetail,
                name: '我要买详细',
            }, {
                path: '/purDetail/:id',
                component: purDetail,
                name: '求购信息详细',
            }, {
                path: '/userIndex',
                component: userIndex,
                name: '个人中心',
                children: [{
                    path: '/user/myInfo',
                    component: myInfo,
                    name: '我的资料',
                }, {
                    path: '/user/myNotice',
                    component: myNotice,
                    name: '我的信息',
                }, {
                    path: '/user/myRed',
                    component: myRed,
                    name: '我的红包',
                }, {
                    path: '/user/myOutRecord',
                    component: myOutRecord,
                    name: '我的支出记录',
                }, {
                    path: '/user/mySaling',
                    component: mySaling,
                    name: '我出售信息',
                }, {
                    path: '/user/myBuying',
                    component: myBuying,
                    name: '我的求购信息',
                }]
            }]
        }

    ],
    // moda: 'history'
})



// routers.beforeEach((to, from, next) => {

//     // NProgress.start()
//     // console.log('to:' + to.path)
//     if (to.path.startsWith('/login')) {
//         // window.localStorage.removeItem('access-user')
//         next()
//     } else {
//         let user = JSON.parse(window.localStorage.getItem('access-user'));

//         if (!user) {
//             next({ path: '/login' })
//         } else {
//             next()
//         }
//     }
// })
export default routers;